﻿<%@ Page Title="" Language="C#" MasterPageFile="~/W_View/PageMaster.Master" AutoEventWireup="true" CodeBehind="S_EvaluatePage.aspx.cs" Inherits="STHPMS1.Web.W_View.Survey.S_EvaluatePage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <%= UiHelper.RefJsFileHtml("/Scripts/Control/datagrid.js")%>
    <%= UiHelper.RefJsFileHtml("/Scripts/Jquery/ajaxfileupload.js")%>

    <script>
        //评定管理操作----------------------------------------------------------------------------------------------------------------------------------------
        //消息提示框
        function showBySite(obj) {
            var inspecid = $('#dg').datagrid('getSelected').Inspecid; //评定名称
            var tableName = $(obj).attr("v")

            $.ajax({
                url: "/api/S_Evaluate/showImportProgress?inspecid=" + encodeURI(inspecid) + "&tableName=" + tableName,
                type: "get",
                complete: function () {
                    $.messager.progress('close');
                },
                success: function (msg) {
                    var data = eval('(' + msg + ')');
                   
                    var htmlstr = "<div style='width:300px;  overflow:auto; '>";
                    var _h = 100; //消息框动态高度
                    $.each(data, function (i, t) {
                        htmlstr += "路线编号:<b>" + t.Name+"</b>";
                        _h += 12;
                        if (t.Up != null)
                        {
                            htmlstr += "<br>&nbsp;&nbsp;[上行]最新导入时间:" + t.Up.Time.substring(0,10);
                            _h += 12;
                            htmlstr += "<br>&nbsp;&nbsp;范围:" + formatPile(t.Up.Min, '') + "&nbsp;~&nbsp;" + formatPile(t.Up.Max, '');
                            _h += 12;
                        }
                        if (t.Down != null) {
                            htmlstr += "<br>&nbsp;&nbsp;[下行]最新导入时间:" + t.Down.Time.substring(0, 10);
                            _h += 12;
                            htmlstr += "<br>&nbsp;&nbsp;范围:" + formatPile(t.Down.Min, '') + "&nbsp;~&nbsp;" + formatPile(t.Down.Max, '');
                            _h += 12;
                        }
                        if (t.All != null) {
                            htmlstr += "<br>&nbsp;&nbsp;[全幅]最新导入时间:" + t.All.Time.substring(0, 10);
                            _h += 12;
                            htmlstr += "<br>&nbsp;&nbsp;范围:" + formatPile(t.All.Min, '') + "&nbsp;~&nbsp;" + formatPile(t.All.Max, '');
                            _h += 12;
                        }
                        htmlstr += "<br><br>";
                        _h += 30;
                    });
                    htmlstr +="</div>"
                    var options = {
                        title: inspecid+"导入信息",
                        width:300,
                        height:_h,
                        msg: htmlstr,
                        showType: 'slide',
                        timeout: 0
                    };
                   
                    $.messager.show(options);
                    //$.messager.alert("",htmlstr,"")
                },

                error: function (msg) {
                    //错误处理
                    $.messager.alert('错误提示', msg.responseText, "error");
                    closeImport();
                }
            });
           
        }
        //格式化评定数据状态
        function formatInspecLJ(val, row) {
            if (val == true) {
                var v = 'S_Subgrd';
                return "<a href='#' v='" + v + "' onclick='showBySite(this);'>查看详情 √</a>"
            }
        }
        function formatInspecSS(val, row) {
            if (val == true) {
                var v = 'S_RDDF';
                return "<a href='#' v='" + v + "' onclick='showBySite(this);'>查看详情 √</a>"
            }
        }
        function formatInspecQSGZW(val, row) {
            if (val == true) {
                var v = 'S_Btstrut';
                return "<a href='#' v='" + v + "' onclick='showBySite(this);'>查看详情 √</a>"
            }
        }
        function formatInspecCZ(val, row) {
            if (val == true) {
                var v = 'S_Rutting';
                return "<a href='#' v='" + v + "' onclick='showBySite(this);'>查看详情 √</a>"
            }
        }
        function formatInspecKH(val, row) {
            if (val == true) {
                var v = 'S_Rdfrc';
                return "<a href='#' v='" + v + "' onclick='showBySite(this);'>查看详情 √</a>"
            }
        }
        function formatInspecPZD(val, row) {
            if (val == true) {
                var v = 'S_Rdrgh';
                return "<a href='#' v='" + v + "' onclick='showBySite(this);'>查看详情 √</a>"
            }
        }
        function formatInspecQD(val, row) {
            if (val == true) {
                var v = 'S_Rdpssi';
                return "<a href='#' v='" + v + "' onclick='showBySite(this);'>查看详情 √</a>"
            }
        }
        function formatInspecLQ(val, row) {
            if (val == true) {
                var v = 'S_Pmds_Asp';
                return "<a href='#' v='" + v + "' onclick='showBySite(this);'>查看详情 √</a>"
            }
        }
        function formatInspecShaS(val, row) {
            if (val == true) {
                var v = 'S_PMDS_S';
                return "<a href='#' v='" + v + "' onclick='showBySite(this);'>查看详情 √</a>"
            }
        }
        function formatInspecSN(val, row) {
            if (val == true) {
                var v = 'S_Pmds_Cem';
                return "<a href='#' v='" + v + "' onclick='showBySite(this);'>查看详情 √</a>"
            }
        }
        //格式化评定管理状态
        function formatInspecState(val, row) {
            if (val == false) {
                return "未评定"
            }
            return "已评定";
        }
        //显示导入界面
        function showUpload() {
            var row = $('#dg').datagrid('getSelected');
            if (!row) {
                $.messager.alert('消息提示', '导入数据时，请选择一行评定项!', 'warning');
                return;
            }
            $('#dlgImport').dialog({ title: "[" + row.Inspecid + "] 导入数据" });
            $('#dlgImport').dialog('open');
        }

        //评定管理初始化(增删改查评定)-------------------------------------------------------------------------------------------
        function search(n, o) {
            var url = '/api/S_Evaluate';
            $('#dg').datagrid({ url: url, pageNumber: 1 });
        }
        $(function () {
            var number = '<%= Page.RouteData.Values["page"] %>';
            var size = '<%= Page.RouteData.Values["size"] %>';

            dataGridBind($('#dg'), '/api/S_Evaluate', '评定管理列表显示', $('#tb'), number, size);

            $('.validatebox-text').bind('blur', function () {
                $(this).validatebox('enableValidation').validatebox('validate');
            });
        })
        //显示新增页面
        function showAdd() {
            var title = "新增评定管理";
            $('#dlg').dialog('open');
        }
        //新增评定信息
        function add() {
            var inspecid = $("#Name").val()//评定名称
            var y = $("#cmbY").combobox("getText")//评定年份
            var m = $("#cmbM").combobox("getText")//评定月份
            if (m == "请选择") {
                m = "";
            }
            else {
                m = "-" + m;
            }
            var date = y + m;

            $.ajax({
                url: "/api/S_Evaluate/add?inspecid=" + encodeURI(inspecid) + "&date=" + date,
                type: "post",
                success: function (msg) {
                    $('#dlg').dialog('close');
                    search(null, null);
                },
                error: function (msg) {
                    //错误处理
                    alert(msg.responseText);
                }
            });
        }
        function del() {
            var row = $('#dg').datagrid('getSelected');
            if (!row) {
                $.messager.alert('消息提示', '删除数据时，请选择一项!', 'warning');
                return;
            }
            deleteData($('#dg'), $('#dlg'), "/api/S_Evaluate");
        }
        //生成评定
        function access() {
            var row = $('#dg').datagrid('getSelected');
            if (!row) {
                $.messager.alert('消息提示', '生成评定时，请选择一项!', 'warning');
                return;
            }

            $.messager.progress({
                title: '请等待',
                msg: '正在处理中...'
            });
            $.ajax({
                url: "/api/S_Inspeaccse/Access?inspecid=" + encodeURI(row.Inspecid),
                type: "post",
                complete: function () {
                    $.messager.progress('close');
                },
                success: function (msg) {
                    $('#dlg').dialog('close');
                    search(null, null);
                },

                error: function (msg) {
                    //错误处理
                    $.messager.alert('错误提示', msg.responseText, "error");
                }
            });
        }
        //评定管理初始化(增删改查评定)结束-------------------------------------------------------------------------------------------


    </script>

    <script>

       

        //导入数据相关操作-----------------------------------------------------------------------------------------------------------
        //上传文件
        function upLoad() {
            //允许上传
            if ($("#linkUpload").text() == "上传") {
                var file = $("#file1").val();//上传文件
                if (file == "") {
                    alert("请选择上传数据");
                    return;
                }
                else {
                    var extStart = file.lastIndexOf(".");
                    var ext = file.substring(extStart, file.length).toUpperCase();
                    if (ext != ".XLS" && ext != ".XLSX") {
                        alert("请上传有效Excel文件");
                        return;
                    }
                }
                //上传
                $.ajaxFileUpload(
               {
                   url: '/api/S_Evaluate/uploadFile', //用于文件上传的服务器端请求地址
                   secureuri: false, //是否需要安全协议，一般设置为false
                   fileElementId: 'file1', //文件上传域的ID
                   dataType: 'string', //返回值类型 一般设置为json
                   success: function (path)  //服务器成功响应处理函数                   {
                   {
                       $("#fileHid").val(path); //将服务器返回的上传路径写入隐藏域
                       $("#linkUpload").text("上传成功");//更改上传按钮
                   },
                   error: function (data, status, e)//服务器响应失败处理函数
                   {
                       alert(e);
                   }
               });
            }
        }

        //保存导入数据
        function saveImport()
        {
            var path = $("#fileHid").val();//服务器的Excel路径
            if (path == "") {
                alert("请上传数据文件");
                return;
            }
            var inspecid = $('#dg').datagrid('getSelected').Inspecid; //评定名称
            var imtType = $("#cmbImportType").combobox("getValue");//导入类型
            $.messager.progress({
                title: '请等待',
                msg: '正在处理中...'
            });
            $.ajax({
                url: "/api/S_Evaluate/saveImport?path=" + encodeURI(path) + "&inspecid=" + encodeURI(inspecid) + "&imtType=" + imtType,
                type: "post",
                complete: function () {
                    $.messager.progress('close');
                },
                success: function (oldCount) {
                    $("#fileHid").val('');//清空服务器的Excel路径
                    $('#dlgImport').dialog('close');
                    closeImport();//关闭导入界面
                    search(null, null);
                    //根据返回值判断是否存在重复数据，提示用户是否保留
                    if(oldCount != "0")
                    {
                        if(confirm("该评定已经存在"+oldCount+"个单元的检测数据,是否更新?") == true)
                        {
                            updateUnit(inspecid, imtType);//删除重复评定单元
                        }
                    }
                },

                error: function (msg) {
                    //错误处理
                    $.messager.alert('错误提示', msg.responseText, "error");
                    closeImport();
                }
            });
        }

        //关闭导入界面
        function closeImport()
        {
            $("#linkUpload").text("上传");//恢复上传按钮
            $('#dlgImport').dialog('close');//关闭导入界面
            $("#fileHid").val('');//清空服务器文件路径
        }

        //删除评定的重复数据
        function updateUnit(inspecid, imtType)
        {
            $.ajax({
                url: "/api/S_Evaluate/updateUnit?inspecid=" + encodeURI(inspecid) + "&imtType=" + imtType,
                type: "post",                
                success: function (msg) {
                    closeImport();
                },

                error: function (msg) {
                    //错误处理
                    $.messager.alert('错误提示', msg.responseText, "error");                   
                }
            });
        }
    </script>

    

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <table id="dg" class="easyui-datagrid content-place" ajaxcached="false">
        <thead>
            <tr>
                <th data-options="field:'Inspecid',width:180">评定名称</th>
                <th data-options="field:'Year_M',width:120">评定时间</th>
                <th data-options="field:'Issub',width:120" formatter='formatInspecLJ'>路基数据导入</th>
                <th data-options="field:'Isrddf',width:120" formatter='formatInspecSS'>沿线设施数据导入</th>
                <th data-options="field:'Isbtstrut',width:120" formatter='formatInspecQSGZW'>桥隧构造物数据导入</th>
                <th data-options="field:'Isrutting',width:120" formatter='formatInspecCZ'>车辙数据导入</th>
                <th data-options="field:'Isrdpssi',width:120" formatter='formatInspecQD'>结构强度数据导入</th>
                <th data-options="field:'Isasphalt',width:140" formatter='formatInspecLQ'>病害数据导入(沥青路面)</th>
                <th data-options="field:'Isgravel',width:140" formatter='formatInspecShaS'>病害数据导入(砂石路面)</th>
                <th data-options="field:'Iscement',width:140" formatter='formatInspecSN'>病害数据导入(水泥路面)</th>
                <th data-options="field:'Isrdfrc',width:120" formatter='formatInspecKH'>抗滑数据导入</th>
                <th data-options="field:'Isrdrgh',width:120" formatter='formatInspecPZD'>平整度数据导入</th>
                <th data-options="field:'Isaccess',width:80" formatter='formatInspecState'>评定状态</th>

            </tr>
        </thead>
    </table>
    <br />
    说明:双击查看详情
    <!--表格数据操作-->
    <div id="tb">
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="showAdd()">添加</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="del()">删除</a>
        <a href="/down" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true">模板下载</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="showUpload()">导入</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="access()">生成评定</a>
     
    </div>


    <!--评定详细页面-->
    <div id="dlg" class="easyui-dialog" title="生成评定名称" style="width: 320px; height: 250px; padding: 10px" closed="true" data-options="
				iconCls: 'icon-save',
				buttons: '#dlg-buttons'
			">
        <form id="fm">
            <table>
                <tr>
                    <td>评定名称:</td>
                    <td>
                        <input id='Name' class='easyui-textbox' data-options="required:true,validType:'MaxLength[36]'" /></td>
                </tr>
                <tr>
                    <td>评定年份:</td>
                    <td>
                        <select id="cmbY" class="easyui-combobox" panelheight="80" style="width: 100px">
                            <option selected="selected"></option>
                            <%for (int i = 1990; i < 2050; i++)
                              { %>
                            <option><%=i%></option>
                            <%} %>
                        </select></td>
                </tr>
                <tr>
                    <td>评定月份:</td>
                    <td>
                        <select id="cmbM" class="easyui-combobox" panelheight="80" style="width: 100px">
                            <option selected="selected">请选择</option>
                            <option>01</option>
                            <option>02</option>
                            <option>03</option>
                            <option>04</option>
                            <option>05</option>
                            <option>06</option>
                            <option>07</option>
                            <option>08</option>
                            <option>09</option>
                            <option>10</option>
                            <option>11</option>
                            <option>12</option>
                        </select></td>
                </tr>
            </table>
        </form>
    </div>
    <!--编辑数据命令-->
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:add()">保存</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:$('#dlg').dialog('close')">取消</a>

    </div>


    <!--导入数据-->
    <div id="dlgImport" class="easyui-dialog" title="导入数据" style="width: 320px; height: 250px; padding: 10px" closed="true" data-options="
				iconCls: 'icon-save',
				buttons: '#dlg-buttonsImport'
			">

        <table>
            <tr>
                <td>数据类型:</td>
                <td>
                    <select id="cmbImportType" class="easyui-combobox" panelheight="80" style="width: 140px"
                        data-options="url:'/api/data/importtype',method:'get',valueField:'id',textField:'text',
                              onLoadSuccess:function(data){ $('#cmbImportType').combobox('setValue',data[0].id);}">
                    </select>
                </td>
            </tr>
            <tr>
                <td>导入源:</td>
                <td>
                    <input id="id_type" type="hidden" />
                    <input id="fileHid" type="hidden" />
                    <input type="file" id="file1" name="file" style="width: 150px" />
                    <a href="javascript:void(0)" id="linkUpload" onclick="javascript:upLoad()">上传</a>
                </td>
            </tr>
        </table>

    </div>
    <!--导入数据命令-->
    <div id="dlg-buttonsImport">
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:saveImport()">确定</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:closeImport()">取消</a>
    </div>
</asp:Content>
